﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.SqlClient;
using System.Data;

namespace DAO
{
    public class TaiKhoanDAO
    {
        public DataTable DangNhap(TaiKhoanDTO _tk)
        {
            DataTable dt = null;
            DataProvider dp = new DataProvider();
            List<SqlParameter> para = new List<SqlParameter>();
            para.Add(new SqlParameter("@tendangnhap", _tk.TenDangNhap));
            para.Add(new SqlParameter("@matkhau", _tk.MatKhau));
            dt = dp.SqlExcuteQuery("sp_DangNhap", para.ToArray());
            return dt;
        }

        public DataTable LayThongTinTaiKhoan_MaTaiKhoan(TaiKhoanDTO _tk)
        {
            DataTable dt = null;
            DataProvider dp = new DataProvider();
            List<SqlParameter> para = new List<SqlParameter>();
            para.Add(new SqlParameter("@MaTaiKhoan", _tk.MaTaiKhoan));
            dt = dp.SqlExcuteQuery("sp_LayThongTinTaiKhoan_MaTaiKhoan", para.ToArray());
            return dt;
        }
        public DataTable LoadTaiKhoan()
        {
            DataTable dt = null;
            DataProvider dp = new DataProvider();
            dt = dp.SqlExcuteQuery("sp_LoadTaiKhoan");
            return dt;
        }
        public DataTable DanhSachChucVu()
        {
            DataTable dt = null;
            DataProvider dp = new DataProvider();
            dt = dp.SqlExcuteQuery("sp_DanhSachChucVu");
            return dt;
        }
        public DataTable DanhSachGioiTinh()
        {
            DataTable dt = null;
            DataProvider dp = new DataProvider();
            dt = dp.SqlExcuteQuery("sp_DanhSachGioiTinh");
            return dt;
        }
        public DataTable TimKiemTaiKhoan(TaiKhoanDTO _tk)
        {
            DataTable dt = null;
            DataProvider dp = new DataProvider();
            List<SqlParameter> para = new List<SqlParameter>();
            para.Add(new SqlParameter("@TenDangNhap", _tk.TenDangNhap));
            dt = dp.SqlExcuteQuery("sp_TimKiemTaiKhoan",para.ToArray());
            return dt;
        }
        public void ThemTaiKhoan(TaiKhoanDTO _tk)
        {
            DataProvider dp = new DataProvider();
            List<SqlParameter> para = new List<SqlParameter>();
            para.Add(new SqlParameter("@TenDangNhap", _tk.TenDangNhap));
            para.Add(new SqlParameter("@MatKhau", _tk.MatKhau));
            para.Add(new SqlParameter("@HoTen", _tk.HoTen));
            para.Add(new SqlParameter("@Cmnd", _tk.Cmnd));
            para.Add(new SqlParameter("@NgaySinh", _tk.NgaySinh));
            para.Add(new SqlParameter("@GioiTinh", _tk.GioiTinh));
            para.Add(new SqlParameter("@DiaChi", _tk.DiaChi));
            para.Add(new SqlParameter("@DienThoai", _tk.DienThoai));
            para.Add(new SqlParameter("@ChucVu", _tk.ChucVu));
            dp.SqlExcuteNonQuery("sp_ThemTaiKhoan", para.ToArray());
        }
        public void XoaTaiKhoan(TaiKhoanDTO _tk)
        {
            DataProvider dp = new DataProvider();
            List<SqlParameter> para = new List<SqlParameter>();
            para.Add(new SqlParameter("@MaTaiKhoan", _tk.MaTaiKhoan));
            dp.SqlExcuteNonQuery("sp_XoaTaiKhoan", para.ToArray());
        }
        public void CapNhatTaiKhoan(TaiKhoanDTO _tk)
        {
            DataProvider dp = new DataProvider();
            List<SqlParameter> para = new List<SqlParameter>();
            para.Add(new SqlParameter("@MaTK", _tk.MaTaiKhoan));
            para.Add(new SqlParameter("@TenDangNhap", _tk.TenDangNhap));
            para.Add(new SqlParameter("@MatKhau", _tk.MatKhau));
            para.Add(new SqlParameter("@HoTen", _tk.HoTen));
            para.Add(new SqlParameter("@Cmnd", _tk.Cmnd));
            para.Add(new SqlParameter("@NgaySinh", _tk.NgaySinh));
            para.Add(new SqlParameter("@GioiTinh", _tk.GioiTinh));
            para.Add(new SqlParameter("@DiaChi", _tk.DiaChi));
            para.Add(new SqlParameter("@DienThoai", _tk.DienThoai));
            para.Add(new SqlParameter("@ChucVu", _tk.ChucVu));
            dp.SqlExcuteNonQuery("sp_CapNhatTaiKhoan", para.ToArray());
        }
    }
}
